package com.kc.web.controller.business;

import com.kc.business.domain.BizTeacherRelationship;
import com.kc.business.service.IBizTeacherRelationshipService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName BizTeacherRelationshipController
 * @Description 师承Controller
 * @Author wangdongliang
 * @Date 2021/5/24 16:57
 */
@RestController
@RequestMapping("/business/teacherRelationship")
public class BizTeacherRelationshipController {
    @Resource
    private IBizTeacherRelationshipService teacherRelationshipService;

    /**
     * 数据新增
     * @param bizTeacherRelationship
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:teacherRelationship:add')")
    @Log(title = "师承数据管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody BizTeacherRelationship bizTeacherRelationship) {
        teacherRelationshipService.add(bizTeacherRelationship);
        return AjaxResult.success();
    }
    /**
     * 数据编辑
     * @param bizTeacherRelationship
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:teacherRelationship:update')")
    @Log(title = "师承数据管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @RepeatSubmit
    public AjaxResult update(@Validated @RequestBody BizTeacherRelationship bizTeacherRelationship) {
        teacherRelationshipService.update(bizTeacherRelationship);
        return AjaxResult.success();
    }

    /**
     * 获取数据列表
     * @param bizTeacherRelationship
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:teacherRelationship:list')")
    @GetMapping("/list")
    public AjaxResult list(BizTeacherRelationship bizTeacherRelationship) {
        List<BizTeacherRelationship> list = teacherRelationshipService.getList(bizTeacherRelationship);
        return AjaxResult.success(list);
    }

    /**
     * 删除师承数据
     */
    @PreAuthorize("@ss.hasPermi('business:teacherRelationship:remove')")
    @Log(title = "师承数据管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Integer id) {
        BizTeacherRelationship teacherRelationship = new BizTeacherRelationship();
        teacherRelationship.setId(id);
        teacherRelationship.setIsDeleted(1);
        return AjaxResult.success(teacherRelationshipService.update(teacherRelationship));
    }
}
